import http from '@/http/index'
// 权限页数据请求
export const userListApi = (params: IListParams): RES<IListModel<List>> => http.get("/admin/list", { params })

//  关闭账号请求
export const switchUserStatusApi = (id: number, status: number): RES<number> => http.post(`/admin/updateStatus/${id}?status=${status}`);
// 添加用户
export const addUserApi = (params: List): RES<number> =>
    http.post("/admin/register", params);

// 编辑用户（获取数据）
export const getUserById = (id: number): RES<List> =>
    http.get(`/admin/${id}`);

//编辑用户数据（修改数据）
export const updateUserApi = (params: List): RES<List> =>
    http.post(`/admin/update/${params.id}`, params);

// 获取全部角色信息
export const getRoleListApi = (): RES<IRoleListData[]> =>
    http.get('/role/listAll');

// 获取指定id用户的角色
export const getRolesByUserIdApi = (adminId: number): RES<IRoleListData[]> => http.get(`/admin/role/${adminId}`)

// 修改指定用户的角色
export const updateUserRolesApi = (adminId: number, roleIds: number[]): RES<number> => http.post(`/admin/role/update?adminId=${adminId}&roleIds=${roleIds.join(',')}`)

// 根据角色名称分页获取角色列表
export const RoleListApi = (params: IListParams): RES<IRoleListModel> => http.get("/role/list", { params })

// 修改角色状态
export const switchRoleStatusApi = (id: number, status: number): RES<number> => http.post(`/role/updateStatus/${id}?status=${status}`);

// 添加角色
export const addRoleApi = (params: IRoleListData): RES<number> => http.post("/role/create", params);


// 获取指定角色（无接口，父传子）


// 修改角色数据
export const updateRoleApi = (params: IRoleListData): RES<number> => http.post(`/role/update/${params.id}`, params);

// 获取指定角色的选中相关资源
export const getRourceRoleApi = (roleId: number): RES<IRourceRole[]> => http.get(`/role/listResource/${roleId}`)

//获取后台角色所有资源
export const resourceListApi = (): RES<IRourceRole[]> => http.get("/resource/listAll")

//获取后台角色所有资源分类
export const resourceAllApi = (): RES<IResourceCategory[]> => http.get("/resourceCategory/listAll")

// 给角色分配资源
export const branchResourceApi = (params: allocResourcePramas): RES<number> => http.post(`/role/allocResource?roleId=${params.roleId}&resourceIds=${params.resourceIds?.join(",")}`)

// 获取菜单页资源
export const treeListApi = (): RES<ItreeMenu[]> => http.get("/menu/treeList");

//角色分配菜单
export const menuResourceApi = (params: allocResourcePramas): RES<number> => http.post(`/role/allocResource?roleId=${params.roleId}&resourceIds=${params.resourceIds?.join(",")}`)


